package com.example.utils;

import cn.dev33.satoken.stp.StpUtil;
import com.example.entity.User;
import com.example.mapper.UserMapper;

/**
 * @Description Sa-Token工具类
 * @Author dingchunlin
 * @Date 2024/6/19 17:00
 * @Version 1.0.0
 */
public class SaUtils {


    /**
     * 获取当前登录用户信息
     * @return 当前登录用户信息
     */
    public static User getLoginUser() {
        Long loginId = Long.valueOf(StpUtil.getLoginId().toString());
        if (loginId!= null) {
            // 从数据库中获取用户信息
            UserMapper userMapper = SpringUtils.getBean(UserMapper.class);
            User user = userMapper.selectById(loginId);
            return user;
        }
        return null;
    }
}
